<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
      table{
        margin: auto;
        margin-top: 150px;
        text-align: center;
      }
      tr:nth-child(1){
        background-color: rgb(4, 119, 176);
        color: #fff;
        font-weight: 700;
      }
      td{
        border: 1px solid #989595;
      }
      .ck:checked{
        width: 13px;
      }
    </style>
</head>
<body>
    <table cellspacing="0" cellpadding="10" width="40%">
        <tr>
          <th class="allCheck">
            <input type="checkbox" name="" id="checkAll"> <span class="all">全选</span>
          </th>
          <th>商品</th>
          <th>商家</th>
          <th>价格</th>
        </tr>
        <tr>
          <td>
            <input type="checkbox" name="check" class="ck">
          </td>
          <td>小米手机</td>
          <td>小米</td>
          <td>￥1999</td>
        </tr>
        <tr>
          <td>
            <input type="checkbox" name="check" class="ck">
          </td>
          <td>小米净水器</td>
          <td>小米</td>
          <td>￥4999</td>
        </tr>
        <tr>
          <td>
            <input type="checkbox" name="check" class="ck">
          </td>
          <td>小米电视</td>
          <td>小米</td>
          <td>￥5999</td>
        </tr>
    </table>
    <script>
        const checkAll=document.querySelector('#checkAll')
        const ck=document.querySelectorAll('.ck')

        checkAll.addEventListener('click',function(){
            for(let i=0;i<ck.length;i++){
              ck[i].checked=checkAll.checked
            }
        })

        for(let i=0;i<ck.length;i++){
          ck[i].addEventListener('click',function(){
            console.log(num=document.querySelectorAll('.ck:checked').length);
            if(num==3){
              checkAll.checked=true
            }
            else{
              checkAll.checked=false
            }
          })
        }
    </script>
</body>
</html>